using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ExtendedCharacterStats : LoadableJSONObject{
	
	public int DR = 0;
	public string DRMaterial = "-";
	
	public bool SetDR(string DR, string material)
	{
		int i;
		
		if(int.TryParse(DR, out i) && material.Length < 7)
		{
			this.DR = i;
			this.DRMaterial = material;
			return true;
		}
		
		return false;
	}
	
	public int SpellResistance = 0;
	
	public bool SetSR(string SR)
	{
		int i;
		
		if(int.TryParse(SR, out i))
		{
			this.SpellResistance = i;
			return true;
		}
		
		return false;
	}
	
	public int Age = 18;
	public float Weight = 180;
	public int Height = 74;
	
	public bool SetAge(string a)
	{
		int i;
		if(int.TryParse(a,out i))
		{
			if(i >= 0 && i <= 99999)
			{
				Age = i;
				return true;
			}
		}
		return false;
	}
	
	public bool SetWeight(string a)
	{
		int i;
		if(int.TryParse(a,out i))
		{
			if(i >= 0 && i <= 99999)
			{
				Weight = i;
				return true;
			}
		}
		return false;
	}
	
	public bool SetHeight(string feet, string inches)
	{
		int f, i;
		if(int.TryParse(feet,out f) && int.TryParse(inches,out i))
		{
			if(i >= 0 && i <= 11 && f >= 0)
			{
				Height = f*12 + i;
				return true;
			}
		}
		return false;
	}
	
	public string HairColor = "Black";
	public string EyeColor = "Brown";
	
	public string SkinColor = "Tan";
	
	public bool SetHairColor(string h)
	{
		if(h == null)
		{
			return false;
		}
		if(h.Length <= 24)
		{
			HairColor = h;
			return true;
		}
		return false;
	}
	public bool SetEyeColor(string h)
	{
		if(h == null)
		{
			return false;
		}
		if(h.Length <= 24)
		{
			EyeColor = h;
			return true;
		}
		return false;
	}
	public bool SetSkinColor(string h)
	{
		if(h == null)
		{
			return false;
		}
		if(h.Length <= 24)
		{
			SkinColor = h;
			return true;
		}
		return false;
	}
	
	public int FlySpeed = 0;
	public string FlyManeuverability = "Cannot Fly";
	
	public int SwimSpeed = 0;
	public int ClimbSpeed = 0;
	public int BurrowSpeed = 0;
	
	public bool SetSpeeds(string fly, string maneuver, string swim, string climb, string burrow)
	{
		int f, s, c, b;
		if(int.TryParse(fly, out f) && int.TryParse(swim, out s) && int.TryParse(climb, out c) && int.TryParse(burrow, out b))
		{
			if(f < 1000 && s < 1000 && c < 1000 && b < 1000 && maneuver.Length < 16)
			{
				FlySpeed = f;
				FlyManeuverability = maneuver;
				SwimSpeed = s;
				ClimbSpeed = c;
				BurrowSpeed = b;
				return true;
			}
		}
		return false;
	}
	
	public int Gold = 0;
	public int Platinum = 0;
	public int Silver = 0;
	public int Copper = 0;
	
	public ExtendedCharacterStats()
	{
	}
	
	public override void Load(string json, string file)
	{
		fileName = file;
		if(json != null)
		{
			Dictionary<string,string> data = (MiniJSON.Json.Deserialize(json) as Dictionary<string,object>).ToDSS();
			
			DRMaterial = data["DRMaterial"];
			SpellResistance = int.Parse(data["SpellResistance"]);
			DR = int.Parse(data["DR"]);
			
			Age = int.Parse(data["Age"]);
			Weight = float.Parse(data["Weight"]);
			
			HairColor = data["HairColor"];
			EyeColor = data["EyeColor"];
			
			SkinColor = data["SkinColor"];
			
			FlySpeed = int.Parse(data["FlySpeed"]);
			FlyManeuverability = data["FlyManeuverability"];
			
			SwimSpeed = int.Parse(data["SwimSpeed"]);
			ClimbSpeed = int.Parse(data["ClimbSpeed"]);
			BurrowSpeed = int.Parse(data["BurrowSpeed"]);
			
			Height = int.Parse(data["Height"]);
			
			Gold = int.Parse(data["Gold"]);
			Platinum = int.Parse(data["Platinum"]);
			Silver = int.Parse(data["Silver"]);
			Copper = int.Parse(data["Copper"]);
		}
	}
	
	public override string ToJSON()
	{
		Dictionary<string,string> data = new Dictionary<string, string>();
		data.Add("DRMaterial", DRMaterial);
		data.Add("SpellResistance", SpellResistance.ToString());
		data.Add("DR", DR.ToString());
		data.Add("Age", Age.ToString());
		data.Add("Weight", Weight.ToString());
		data.Add("HairColor", HairColor.ToString());
		data.Add("EyeColor", EyeColor.ToString());
		data.Add("SkinColor", SkinColor.ToString());
		data.Add("FlySpeed", FlySpeed.ToString());
		data.Add("FlyManeuverability", FlyManeuverability.ToString());
		data.Add("SwimSpeed", SwimSpeed.ToString());
		data.Add("ClimbSpeed", ClimbSpeed.ToString());
		data.Add("BurrowSpeed", BurrowSpeed.ToString());
		data.Add("Height", Height.ToString());
		data.Add("Platinum", Platinum.ToString());
		data.Add("Gold", Gold.ToString());
		data.Add("Silver", Silver.ToString());
		data.Add("Copper", Copper.ToString());
		return MiniJSON.Json.Serialize(data);
	}
}
